package com.xuecheng.content.service.impl;


import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.xuecheng.api.content.model.dto.TeachplanMediaDTO;
import com.xuecheng.api.teaching.model.dto.TeachplanWorkDTO;
import com.xuecheng.common.domain.code.CommonErrorCode;
import com.xuecheng.common.domain.response.RestResponse;
import com.xuecheng.content.convert.TeachplanMediaConvert;
import com.xuecheng.content.convert.TeachplanWorkConvert;
import com.xuecheng.content.entity.TeachplanMedia;
import com.xuecheng.content.entity.TeachplanWork;

import com.xuecheng.content.mapper.TeachplanWorkMapper;
import com.xuecheng.content.service.TeachplanWorkService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import org.springframework.util.CollectionUtils;
import org.springframework.util.ObjectUtils;

import java.util.Collections;
import java.util.List;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author itcast
 */
@Slf4j
@Service
public class TeachplanWorkServiceImpl extends ServiceImpl<TeachplanWorkMapper, TeachplanWork> implements TeachplanWorkService {
    @Override
    public RestResponse<List<TeachplanWorkDTO>> getByWorkId4s(Long workId) {
            // 1.判断关键数据
            if (ObjectUtils.isEmpty(workId)) {
                return RestResponse.validfail(CommonErrorCode.E_100101);
            }

            // 2.根据workId获得数据
            LambdaQueryWrapper<TeachplanWork> queryWrapper = new LambdaQueryWrapper<>();
            queryWrapper.eq(TeachplanWork::getWorkId, workId);

            List<TeachplanWork> teachplanWork = this.list(queryWrapper);

            List<TeachplanWorkDTO> dtos = Collections.emptyList();
            if (!(CollectionUtils.isEmpty(teachplanWork))) {
                dtos = TeachplanWorkConvert.INSTANCE.entitys2dtos(teachplanWork);
            }
            RestResponse<List<TeachplanWorkDTO>> success = RestResponse.success(dtos);
            return success;
        }
    }
